package controle;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JButton;
import presentation.NoteDialog;
import abstraction.Cours;

/** controleur appelé lors de la modification d'une note
 * 
 * @author PICOSSON
 *
 */
public class ControlJButtonEditNote implements Observer, ActionListener {

	private Cours modele;
	private JButton button;
	private Frame parent;

	public ControlJButtonEditNote(Frame parent, Cours modele, JButton button) {
		this.modele = modele;
		this.button = button;
		this.parent = parent;
		button.setEnabled(false);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		NoteDialog noteDialog = new NoteDialog(parent, modele);
		noteDialog.setVisible(true);
	}

	@Override
	public void update(Observable o, Object message) {
		Integer iMessage = (Integer) message;
		if (iMessage == Cours.CHANGEMENT_ETUDIANT_COURANT || iMessage == Cours.CHANGEMENT_EVALUATION_COURANTE) {
			if (modele.getEtudiantCourant() == null ||modele.getEvaluationCourante() == -1)
				button.setEnabled(false);
			else
				button.setEnabled(true);
		}
	}

}
